# makfile configuration
NAME            = utils
OBJECTS         = utils.o display.o
#should be 149, waiting for wsim
CPU             = msp430x149

# Includes necessaire pour les appels systemes
OSDIR		= ../os
RTOSDIR		= $(OSDIR)/OS/
PORTDIR         = $(OSDIR)/Ports/MSP430/F1611/GNU

INCDIRS		= -I$(OSDIR) -I$(PORTDIR) -I$(RTOSDIR)

# default flags for compilation
DEFAULT_FLAGS	= -mmcu=${CPU} $(INCDIRS) -O2 -Wall -g

# use when building the entire program
CFLAGS          = ${DEFAULT_FLAGS}

# use when building the test exe
exe: CFLAGS = $(DEFAULT_FLAGS) -DEXE_UTILS

#switch the compiler (for the internal make rules)
CC              = msp430-gcc

.PHONY: all FORCE clean download download-jtag download-bsl dist

#all should be the first target. it's built when make is run without args
all: ${OBJECTS}

exe:  ${NAME}.elf ${NAME}.a43 ${NAME}.lst

#confgigure the next line if you want to use the serial download
download: download-jtag
#download: download-bsl

run: 	${NAME}.elf
	wsim-ot1 --ui ${NAME}.elf

#additional rules for files
${NAME}.elf: ${OBJECTS}
	${CC} -mmcu=${CPU} -o $@ ${OBJECTS}

${NAME}.a43: ${NAME}.elf
	msp430-objcopy -O ihex $^ $@

${NAME}.lst: ${NAME}.elf
	msp430-objdump -dSt $^ >$@

${NAME}.dmp: ${NAME}.elf
	msp430-objdump -d $^ >$@

.s: .c
	${CC} -S $(CFLAGS) $^ >$@

download-jtag: all
	msp430-jtag -e ${NAME}.elf

download-bsl: all
	msp430-bsl -e ${NAME}.elf

clean:
	rm -f ${NAME}.elf ${NAME}.a43 ${NAME}.lst ${OBJECTS} wsim-* *~

#backup archive
dist:
	tar czf LCD.tgz *.c *.h  Makefile

#dummy target as dependecy if something has to be build everytime
FORCE:

#project dependencies
utils.c: resources.h 

.o: .c 
